package com.catmiao.spark.rdd.operator.transform

import org.apache.spark.rdd.RDD
import org.apache.spark.{HashPartitioner, SparkConf, SparkContext}

/**
 * @title: RDD_Operator_01_transform
 * @projectName spark_study
 * @description: TODO
 * @author ChengMiao
 * @date 2024/2/2 11:48
 */
object RDD_Operator_14_transform {

  def main(args: Array[String]): Unit = {
    val sparkCon = new SparkConf().setMaster("local[*]").setAppName("rdd")

    val sparkContext = new SparkContext(sparkCon)


    val rdd = sparkContext.makeRDD(List(("a", 1), ("b", 2), ("a", 3), ("a", 4)))

    // reduceByKey 相同key的数据，进行value聚合的操作
    val rdd2: RDD[(String, Int)] = rdd.reduceByKey((x: Int, y: Int) => x + y)

    rdd2.collect().foreach(println)

    sparkContext.stop()
  }

}
